cmake_minimum_required(VERSION 2.8.12)

# Set the default build type to Release if not specified
if (NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif()

# Set C++ standard to C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Define project name and language
project(mallochook LANGUAGES CXX)

# Check if the platform is Windows
if (WIN32)
    # Compiler options for Windows
    add_compile_options(/Zi /W3 /WX /EHsc)
    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG")
else()
    # Compiler options for other platforms (Linux, MacOS)
    add_compile_options(-g -Wall -Wextra -Werror=return-type)
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -rdynamic")
endif()

# Add the shared library
add_library(mallochook SHARED CheckMemory.cpp)

# Add the executable
add_executable(demo demo.cpp)

# Link the library with the executable
target_link_libraries(demo PRIVATE mallochook)

